//
//  NaviTopTurnImageView.m
//  one_buy_guizhou_ios
//
//  Created by xu yao on 2021/2/2.
//  Copyright © 2021 杨帅. All rights reserved.
//

#import "NaviTopTurnImageView.h"
#import "UIView+Extension.h"

@interface NaviTopTurnImageView ()

@end

@implementation NaviTopTurnImageView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor colorWithRed:29.0/255.0 green:38.0/255.0 blue:49.0/255.0 alpha:1];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 8;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    [self addSubview:self.topTurnImageView];
    [self addSubview:self.topRemainLabel];
    [self addSubview:self.goLabel];
    [self addSubview:self.topRoadLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.topTurnImageView.size = CGSizeMake(60, 60);
    self.topTurnImageView.origin = CGPointMake(20, 20);
    
    [self.topRemainLabel sizeToFit];
    self.topRemainLabel.top = 12;
    self.topRemainLabel.left = self.topTurnImageView.right + 20;
    
    [self.goLabel sizeToFit];
    self.goLabel.bottom = self.topRemainLabel.bottom - 4;
    self.goLabel.left = self.topRemainLabel.right + 10;
    
    [self.topRoadLabel sizeToFit];
    self.topRoadLabel.width = MIN(self.width - self.topRemainLabel.left - 10, self.topRoadLabel.width);
    self.topRoadLabel.bottom = self.topTurnImageView.bottom;
    self.topRoadLabel.left = self.topRemainLabel.left;
}

#pragma mark 懒加载
- (UIImageView *)topTurnImageView {
    if (!_topTurnImageView) {
        _topTurnImageView = [[UIImageView alloc] init];
    }
    return _topTurnImageView;
}

- (UILabel *)topRemainLabel{
    if (!_topRemainLabel) {
        _topRemainLabel = [[UILabel alloc] init];
        _topRemainLabel.textColor = [UIColor whiteColor];
        _topRemainLabel.font = [UIFont systemFontOfSize:40];
        NSMutableAttributedString *attStr = [[NSAttributedString alloc] initWithString:@"0米"].mutableCopy;
        [attStr addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:20]} range:NSMakeRange(1, 1)];
        _topRemainLabel.attributedText = attStr;
    }
    return _topRemainLabel;
}

- (UILabel *)goLabel{
    if (!_goLabel) {
        _goLabel = [[UILabel alloc] init];
        _goLabel.textColor = [UIColor colorWithWhite:1 alpha:0.7];
        _goLabel.font = [UIFont systemFontOfSize:20];
        _goLabel.text = @"进入";
    }
    return _goLabel;;
}

- (UILabel *)topRoadLabel{
    if (!_topRoadLabel) {
        _topRoadLabel = [[UILabel alloc] init];
        _topRoadLabel.textColor = [UIColor whiteColor];
        _topRoadLabel.font = [UIFont systemFontOfSize:20];
        _topRoadLabel.text = @"无名路";
    }
    return _topRoadLabel;
}

@end
